import 'package:flutter/material.dart';

enum SelectionStyle {
  none,
  row,
  column,
  wrap,
  list,
}

enum SelectionItemStyle {
  none,
  radio,
  checkbox,
  input,
  date,
  custom,
  tag,
}

class SelectionModel {
  String text;
  String val;
  bool isMutiable;
  bool isSelected;
  bool isShow;
  List<SelectionModel>? list;
  List<int>? choosedIndexs;
  SelectionStyle style;
  SelectionItemStyle itemStyle;
  String? title;
  int rowCount;
  int? relateTag;
  int tag = 0;

  ///用于自定义
  Widget? child;

  SelectionModel({
    required this.text,
    this.val = '',
    this.isMutiable = false,
    this.isSelected = false,
    this.isShow = false,
    this.list,
    this.choosedIndexs,
    this.style = SelectionStyle.row,
    this.itemStyle = SelectionItemStyle.none,
    this.child,
    this.title,
    this.rowCount = 1,
    this.tag = 0,
    this.relateTag,
  });

  factory SelectionModel.copy(SelectionModel md) {
    return SelectionModel(
      text: md.text,
      val: md.val,
      isMutiable: md.isMutiable,
      isSelected: md.isSelected,
      isShow: md.isShow,
      list: md.list?.map((e) => SelectionModel.copy(e)).toList(),
      choosedIndexs: md.choosedIndexs,
      style: md.style,
      itemStyle: md.itemStyle,
      child: md.child,
      title: md.title,
      rowCount: md.rowCount,
    );
  }
}

class SelectionResultModel {
  String key;
  String? val;
  List<SelectionResultModel>? items;
  SelectionResultModel({
    required this.key,
    this.val,
    this.items,
  });

  String _description = '';
  String get descrption {
    toString();
    return _description;
  }

  @override
  String toString() {
    _description = '标题：$key\n$val';
    itemsString(items);
    return _description;
  }

  void itemsString(List<SelectionResultModel>? items) {
    if (items == null) {
      return;
    }

    if (items.where((e) => e.items != null).isNotEmpty) {
      for (var i = 0; i < items.length; i++) {
        var m = items[i];
        if (m.items != null) {
          _description += '标题：${m.key}\n';
          itemsString(m.items);
        } else {
          _description += '标题：${m.key}\n${m.val}\n';
        }
      }
    } else {
      for (var m in items) {
        _description += '标题：${m.key}\n${m.val}\n';
      }
    }
  }
}
